package com.jiahe.blog.model.response;

import com.jiahe.blog.model.StatusConst;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
public class BlogResponse<T> implements Serializable {

    private boolean success;

    private Integer code;

    private String message;

    private T data;


    public static  <T>  BlogResponse<T> success(T data){
        BlogResponse<T> response = new BlogResponse<>();
        response.setCode(StatusConst.OK);
        response.setSuccess(true);
        response.setMessage("操作成功");
        response.setData(data);
        return response;
    }

    public static  <T>  BlogResponse<T> success(String message, T data){
        BlogResponse<T> response = new BlogResponse<>();
        response.setCode(StatusConst.OK);
        response.setSuccess(true);
        response.setMessage(message);
        response.setData(data);
        return response;
    }


    public static <T> BlogResponse<T> error(String message){
        BlogResponse<T> response = new BlogResponse<>();
        response.setCode(StatusConst.ERROR);
        response.setSuccess(false);
        response.setMessage(message);
        response.setData(null);
        return response;
    }

    public static <T> BlogResponse<T> error(Integer stateCode,String message){
        BlogResponse<T> response = new BlogResponse<>();
        response.setCode(stateCode);
        response.setSuccess(false);
        response.setMessage(message);
        response.setData(null);
        return response;
    }
}
